#ifndef DEEPSEEK_SERVER_H
#define DEEPSEEK_SERVER_H

#include "llm_base.h"
#include <nlohmann/json.hpp>

// #define DP_API_URL "http://dpserver.a1.luyouxia.net:25332/api/chat"

#define DP_API_URL "http://192.168.31.253:11434/api/chat"



class DeepseekServer : public LlmBase{
    static std::string willingBuffer;
    static std::string buffer;
    static bool is_post_done;
    static bool isResponse; // 是否遇到了"{response:"

    static std::function<void(const std::string&)> user_callback;
    static std::function<void(const std::string&)> user_stream_callback;

public:
    DeepseekServer() : LlmBase(){
        buffer.clear();
        isResponse = false;
        is_post_done = true;

        // 设置请求 URL
        curl_easy_setopt(curl, CURLOPT_URL, DP_API_URL);
    }
    ~DeepseekServer(){}

    void setUserCallback(std::function<void(const std::string&)> func) {
        user_callback = func;
    }

    void setUserStreamCallback(std::function<void(const std::string&)> func) {
        user_stream_callback = func;
    }

    bool postRequest(const std::string& question);

    // 判断病人是否已经结束检查并返回病房
    bool check_patient_ready_to_go_back(const std::string& question, std::string & llmRet);

    // 判断病人是否有继续对话的意愿
    bool checkPatientWillingToCotinue(const std::string& question);

private:
    static void parseResponse(const std::string& response);

    static void addToBuffer(const std::string& content);

    static void willingAddToBuffer(const std::string& content);

    static void addToJsonBuffer(const std::string& content);

    static size_t willingWriteCallback(
        void* ptr, size_t size, size_t nmemb, void* userp);

    static size_t check_writeCallback(void* ptr, size_t size, size_t nmemb, void* userp);

    static size_t writeCallback(void* ptr, size_t size, size_t nmemb, void* userp);

    static void willingParseResponse(const std::string& response);
};



#endif // DEEPSEEK_SERVER_H
